import { createRouter, createWebHistory } from "vue-router";
import NoteView from "../pages/note/NoteView.vue";
import PluginView from "../pages/plugin/PluginView.vue";
import TaskView from "../pages/task/TaskView.vue";
import PipelineView from "@/pages/pipeline/PipelineView.vue";
import DatasetView from "../pages/dataset/DatasetView.vue";
import PublishView from "../pages/publish/PublishView.vue";
import LoginView from "@/pages/user/LoginView.vue";
import LogoutView from "@/pages/user/LogoutView.vue";
import DataTable from '@/pages/dataset/components/DataTable.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      name: "home",
      component: NoteView,
    },
    {
      path: "/data",
      name: "data",
      component: DataTable,
    },
    {
      path: "/login",
      name: "login",
      component: LoginView,
    },
    {
      path: "/logout",
      name: "logout",
      component: LogoutView,
    },
    {
      path: "/note",
      name: "note",
      component: NoteView,
    },
    {
      path: "/plugin",
      name: "plugin",
      component: PluginView,
    },

    {
      path: "/dataset",
      name: "dataset",
      component: DatasetView,
    },
    {
      path: "/task",
      name: "task",
      component: TaskView,
    },
    {
      path: "/pipeline",
      name: "pipeline",
      component: PipelineView,
    },
    {
      path: "/publish",
      name: "publish",
      component: PublishView,
    },
  ],
});

router.beforeEach((to, from, next) => {
  const isLogin = localStorage.token ? true : false;
  // console.log("isLogin:", isLogin);
  // if (to.path == "/login" && isLogin) {
  if (to.path == "/login" && isLogin) {
    next("/");
  } else if (to.path != "/login" && !isLogin) {
    next("/login");
  } else {
    next();
    // 这里可以添加一些权限控制逻辑
  }
});

export default router;
